<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>订单管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link type="text/css" rel="stylesheet" href="${staticPath}/layui/css/layui.css">
	<link type="text/css" rel="stylesheet" href="${staticPath}/layui/modules/css/task.css">
	<link type="text/css" rel="stylesheet" href="${staticPath}/layui/modules/css/common.css">
	<style>
		td{ text-align:center;}
	</style>
</head>
<body style="padding:0 30px;">
<blockquote class="layui-elem-quote" style=" border-left: 0px solid #FFFFFF; background-color: #FFFFFF">
	<img src="${staticPath}/layui/modules/images/shop/team.png" style="margin-left: -25px;"> 商户个人中心
</blockquote>
<blockquote class="layui-elem-quote">
	订单管理
</blockquote>
<div class="task_main clearall">
	<ul class="task_nav clearall">
		<li>
			日期
		</li>
		<li>
			<input type="text" class="layui-input" id="createDate" style="width: 200px" readonly="readonly">
			<button class="layui-btn layui-btn-normal" id="search">查询</button>
		</li>
		<li class="li-right">
			<button class="layui-btn layui-btn-normal" id="bale_export">分组下载</button>
		</li>
	</ul>
	<ul class="order-nav" id="order-nav">

	</ul>
	<table class="layui-table" id="task-order-list" lay-skin="nob">
		<thead >
		<tr>
			<th style="border-left:2px solid #2b90fe;">
				<input type="checkbox" lay-skin="primary" lay-filter="layTableAllChoose">序号
			</th>
			<th >任务编号</th><th style="text-align:center;">店铺名称</th><th style="text-align:center;">客单价(元)</th><th style="text-align:center;">客单价备注</th><th style="text-align:center;">打包日期</th>
			<th style="text-align:center;">主图</th><th style="text-align:center;">关键词1</th><th style="text-align:center;">关键词2</th><th style="text-align:center;">关键词3</th><th style="text-align:center;">关键词4</th><th style="text-align:center;">关键词5</th>
			<th style="text-align:center;">筛选条件</th>
			<th style="text-align:center;">城市合伙人</th>
		</tr>
		</thead>
		<tbody id="tbody">
		</tbody>
	</table>
	<div id="page"></div>
</div>
<script src="${staticPath}/layui/layui.js"></script>
<script>
    layui.use(['laypage','jquery','layer','laytpl','form','laydate'], function(){
        var laypage = layui.laypage,$ = layui.jquery,layer = layui.layer,laytpl = layui.laytpl,form = layui.form,laydate = layui.laydate;
        var param = {
            'page.size':5,
            'page.pn':1,
            'order':'asc'
        }
        renderTable(param);
        function renderTable(param){
            layer.load(1);
            $.ajax({
                url: '${adminPath}/client/bale/ajaxListBale',
                data:param,
                type: "POST",
                dataType: "JSON",
                success: function(data){
                    layer.closeAll('loading');
                    laypage.render({
                        elem: 'page'
                        ,count: data.total
                        ,limit: param['page.size']
                        ,limits:[5,10,15,20]
                        ,curr: param['page.pn']
                        ,theme: '#1E9FFF'
                        ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                        ,jump: function(obj,first){
                            param['page.pn']=obj.curr
                            $("input[lay-filter=layTableAllChoose]").removeAttr("checked");
                            //首次不执行
                            if(!first){
                                renderTable(param);
                            }
                        }
                    });
                    var getTpl = table.innerHTML,view = document.getElementById('tbody');
                    laytpl(getTpl).render(data, function(html){
                        view.innerHTML = html;
                    });
                    var rows = {};
                    $.each(data.results, function(index, item){
                        rows[item.id]=item;
                    });
                    $("#tbody").data("rows",rows);
                },
                error: function () {
                    layer.closeAll('loading');
                    layer.msg("未知错误，请联系管理员！",{icon: 2});
                }
            });
        }

        $("#search").click(function(){
            renderTable(param);
        });

        $("#bale_order").bind({
            click:function(){
                layer.confirm('确认打包？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    layer.load(1);
                    $.ajax({
                        url: '${adminPath}/client/bale/baleOrder',
                        type: "POST",
                        dataType: "JSON",
                        success: function(result){
                            layer.closeAll('loading');
                            if(result.ret==0){
                                layer.alert(result.msg, {icon: 0, title:'提示',end: function(){
                                        renderTable(param);
                                    }});
                            }else{
                                layer.alert(result.msg, {icon: 0, title:'警告'});
                            }

                        },
                        error: function () {
                            layer.closeAll('loading');
                            layer.msg("未知错误，请联系管理员！",{icon: 2});
                        }
                    });
                }, function(){

                });
            }
        })

        $("#bale_export").bind({
            click:function(){
                var url= "${adminPath}/client/bale/group";
                var createDate = $("#createDate").val();
                if(createDate==''){
                    alert("请选择日期");
                    return false;
				}
                url = url+'?createDate='+createDate
                window.open(url);
            }
        });

        laydate.render({
            elem: '#createDate',
			value:new Date(),
            done: function(value, date, endDate){
                if(value==""){
                    delete param['query.createDate||custom'];
                }else{
                    param['query.createDate||custom']=value;
                }
            }
        });
        $("input[lay-filter=layTableAllChoose]").bind({
            change:function(){
                if($(this).is(':checked')){
                    $("input[name=layTableCheckbox]").prop("checked",true);
                }else{
                    $("input[name=layTableCheckbox]").removeAttr("checked");
                }
            }
        });
        $("#tbody").on('change', "input[name=layTableCheckbox]",function(){
            var check = true;
            $.each($("input[name=layTableCheckbox]"),function(i,obj){
                if(!$(obj).is(':checked')){
                    check=false;
                }
            })
            if(check){
                $("input[lay-filter=layTableAllChoose]").prop("checked",true);
            }else{
                $("input[lay-filter=layTableAllChoose]").removeAttr("checked");
            }
        });
    })
</script>
<script id="table" type="text/html">
	{{#  layui.each(d.results, function(index, item){ }}
	<tr>
		<td><input type="checkbox"  lay-skin="primary" name="layTableCheckbox" value="{{item.id}}">{{index+1}} </td>
		<td>{{item.number}}</td>
		<td>{{item.shop_name}}</td>
		<td>{{item.price}}</td>
		<td>{{item.title}}</td>
		<td>{{item.create_date}}</td>
		<td>
			<img src="{{item.img_url}}" />
		</td>
		<td>{{item.keyword}}</td>
		<td>{{item.keyword2}}</td>
		<td>{{item.keyword3}}</td>
		<td>{{item.keyword4}}</td>
		<td>{{item.keyword5}}</td>
		<td>{{item.offer_link}}</td>
		<td>{{item.remarks}}</td>
	</tr>
	{{#  }); }}
	{{#  if(d.results.length === 0){ }}
	<div class="layui-table-body layui-table-main">
		<div class="layui-none">无数据</div>
	</div>
	{{#  } }}
</script>
</body>
</html>